<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 
<script>
	var setting = {
		data : {
			simpleData : {
				enable : true,
				idKey : "id",
				pIdKey:"pid",
				rootId : "0"
			}
		},
	callback:{
		onClick: zTreeOnClick
	}
	}
	function zTreeOnClick(event, treeId, treeNode) {
		var line ="<div class='checkbox-inline'><label> <input name='receiverId' type='checkbox' checked='checked' value="+(treeNode.id-100)+">"+treeNode.name+" <i class='fa fa-square-o'></i></label></div>";
		$(".messageAccepter").append(line);
	    //alert(treeNode.id + "," + treeNode.name);
	};
	$.ajax({
		url : "getEmployeetree",
		type : "get",
		dataType : "json",
		success : function(json) {
			$.fn.zTree.init($("#departmenttTree"), setting, json);
		}
	}
)
</script>
<script type="text/javascript">
function saveAction(){
    document.name.action= 'messagesave';
    document.name.submit();
}
function addAction(){
    document.name.action= 'messageupdate';
    document.name.submit();
}
</script>
<div class="row">
	<div class="col-xs-12 col-sm-12">
		<div class="box">
			<div class="box-header">
				<div class="box-name">
					<i class="fa fa-search"></i> <span>邮件箱</span>

				</div>
				<div class="box-icons">
					<a class="collapse-link"> <i class="fa fa-chevron-up"></i>
					</a> <a class="expand-link"> <i class="fa fa-expand"></i>
					</a> <a class="close-link"> <i class="fa fa-times"></i>
					</a>
				</div>
				<div class="no-move"></div>
			</div>
			<c:if test="${ messagefecthId!=null}">
			
			<!--邮件编辑-->
		<div class="box-content col-sm-10">
				<h4 class="page-header">邮件编写</h4>
				<form class="form-horizontal" role="form" action="#" name="name">
					<div class="row form-group">
						<label class="col-sm-2 control-label">收件人：</label>
						<div class=" col-sm-10">
						<div class="messageAccepter col-sm-6">
						</div>
						<div class="col-sm-2">
						<input type="submit" id="reset" style="display:inline" value="重置"/>
						</div>
					</div>
					</div>
						
					<div class="form-group">
						<label class="col-sm-2 control-label">标题</label>
						<div class="col-sm-8">
							<input type="text" class="form-control" placeholder="标题"
								data-toggle="tooltip" data-placement="bottom"
								title="Tooltip for name" name="title" value="${messagefecthId.title }">
						</div>
						<div class="col-sm-2 control-label"></div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label" for="form-styles">内容</label>
						<div class="col-sm-10">
							<textarea name="content" class="form-control" rows="5" id="wysiwig_simple">${messagefecthId.content}</textarea>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label">重要程度</label>
						<div class="col-sm-3">
							<select class="populate placeholder"
								id="s2_country" name="level">
								<option value="1">一般</option>
								<option value="2">重要</option>
								<option value="3">紧急</option>

							</select>
						</div>
					</div>
					<div class="clearfix"></div>
					<div class="form-group">
						<div class="col-sm-offset-2 col-sm-2">
							<button type="reset" class="btn btn-default btn-label-left">
								<span><i class="fa fa-clock-o txt-danger"></i></span> 取消
							</button>
						</div>
						<div class="col-sm-4">
							<button type="button" class="btn btn-warning btn-label-left" onclick="saveAction()">
								<span><i class="fa fa-clock-o"></i></span> 保存到草稿箱
							</button>
						</div>
						<div class="col-sm-4">
							<button type="button" class="btn btn-primary btn-label-left" onclick="addAction()">
								<span><i class="fa fa-clock-o"></i></span> 发送
							</button>
						</div>
					</div>
				</form>
			</div>
			</c:if>
			<c:if test="${messagefecthId==null }">
			<!--新建邮件  -->
			<div class="box-content col-sm-10">
				<h4 class="page-header">新建邮件</h4>
				<form class="form-horizontal" role="form" action="#" name="name">
					<div class="row form-group">
						<label class="col-sm-2 control-label">收件人：</label>
						<div class=" col-sm-10">
						<div class="messageAccepter col-sm-6">
						</div>
						<div class="col-sm-2">
						<input type="submit" id="reset" style="display:inline" value="重置"/>
						</div>
					</div>
					</div>
						
					<div class="form-group">
						<label class="col-sm-2 control-label">标题</label>
						<div class="col-sm-8">
							<input type="text" class="form-control" placeholder="标题"
								data-toggle="tooltip" data-placement="bottom"
								title="Tooltip for name" name="title">
						</div>
						<div class="col-sm-2 control-label"></div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label" for="form-styles">内容</label>
						<div class="col-sm-10">
							<textarea name="content" class="form-control" rows="5" id="wysiwig_simple"></textarea>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label">重要程度</label>
						<div class="col-sm-3">
							<select class="populate placeholder"
								id="s2_country" name="level">
								<option value="1">一般</option>
								<option value="2">重要</option>
								<option value="3">紧急</option>

							</select>
						</div>
					</div>
					<div class="clearfix"></div>
					<div class="form-group">
						<div class="col-sm-offset-2 col-sm-2">
							<button type="reset" class="btn btn-default btn-label-left">
								<span><i class="fa fa-clock-o txt-danger"></i></span> 取消
							</button>
						</div>
						<div class="col-sm-4">
							<button type="button" class="btn btn-warning btn-label-left" onclick="saveAction()">
								<span><i class="fa fa-clock-o"></i></span> 保存到草稿箱
							</button>
						</div>
						<div class="col-sm-4">
							<button type="button" class="btn btn-primary btn-label-left" onclick="addAction()">
								<span><i class="fa fa-clock-o"></i></span> 发送
							</button>
						</div>
					</div>
				</form>
			</div>
			</c:if>
			<div id="sidebar-right" class="box-content col-sm-2">
				<ul class="nav main-menu">
				<dl >收件人</dl>
				</ul>
				<ul id="departmenttTree" class="ztree"></ul>
			</div>
		</div>
	</div>
</div>

<script type="text/javascript">
	// Run Select2 plugin on elements
	function DemoSelect2() {
		$('#s2_with_tag').select2({
			placeholder : "Select OS"
		});
		$('#s2_country').select2();
	}
	// Run timepicker
	function DemoTimePicker() {
		$('#input_time').timepicker({
			setDate : new Date()
		});
	}
	$(document).ready(function() {
		// Create Wysiwig editor for textare
		TinyMCEStart('#wysiwig_simple', null);
		TinyMCEStart('#wysiwig_full', 'extreme');
		// Add slider for change test input length
		FormLayoutExampleInputLength($(".slider-style"));
		// Initialize datepicker
		$('#input_date').datepicker({
			setDate : new Date()
		});
		// Load Timepicker plugin
		LoadTimePickerScript(DemoTimePicker);
		// Add tooltip to form-controls
		$('.form-control').tooltip();
		LoadSelect2Script(DemoSelect2);
		// Load example of form validation
		LoadBootstrapValidatorScript(DemoFormValidator);
		// Add drag-n-drop feature to boxes
		WinMove();
	});
</script>
